package com.baike.controller;


import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

@ServerEndpoint("/websocket/{uid}")
public class MyWebSocket {

    @OnOpen
    public void onOpen(Session session, @PathParam("uid")String uid) throws IOException {
        session.getBasicRemote().sendText(uid + "，你好，欢迎来到webSocket！" );
    }
    @OnClose
    private void onClose(){
        System.out.println("关闭连接");
    }

    @OnMessage
    public void onMessage(String message ,Session session) throws IOException {
        System.out.println("收到消息：" +message);
        session.getBasicRemote().sendText("消息已经收到");


    }

    @OnError
    private void onError(Session session,Throwable error){
        System.out.println("发生错误");
        error.printStackTrace();;
    }
}
